const obj = { //被代理的对象
        name: '_island',
        score: 59
    }
    // const objproxy = new Proxy(obj, {})
    // console.log(objproxy);
const objproxy = new Proxy(obj, {
    get: function(target, key) {
        console.log(`捕获到对象获取${key}属性的值操作`);
        return target[key];
    },
    //写操作
    //对象的访问拦截，捕捉器set
    set: function(target, key, val) {
        // target[key] = val
        if (key == 'age') {
            if (typeof val == 'number') {
                target[key] = val
            } else {
                throw new TypeError('该属性的值必须是number类型')
                    // console.warn('该属性的值必须是number类型');
            }
        } else {
            target[key] = val
        }
    }
})
console.log(objproxy.name)
try {
    objproxy.age = 'nihao'
} catch (e) {
    console.warn(e);
}

console.log(objproxy.age)